package com.sgb.knowledgeshare.viewmodel;

import androidx.lifecycle.ViewModel;
import com.sgb.knowledgeshare.ShareConfig;
import com.sgb.knowledgeshare.entity.ShareDictEntity3;
import com.sgb.knowledgeshare.view.fragment.AttentionFragment;
import com.sgb.knowledgeshare.weight.ControllerView;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.VideoBean;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;
import com.swgk.core.view.entity.VideoListEntity;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class AttentionModel extends ViewModel {
    AttentionFragment attentionfragment;
    private ArrayList<Long> delectList;

    public void setActivity(AttentionFragment attentionFragment) {
        attentionfragment = attentionFragment;
    }

    //    获取所有视频数据信息
    public void getFirstPageList(String page,String type) {
        Map map = new HashMap();
        map.put("pageNum", page);//longitude
        map.put("pageSize", 10);
        map.put("type",type );
        DialogHelper.showProgressDialog(attentionfragment.getContext(), null, "加载中...", 0, true, null).setCanceledOnTouchOutside(false);
        ShareConfig.getInstance().getApi().getFirstPageList(map).enqueue(new ICallBack<BaseEntity<VideoListEntity>>() {
            @Override
            public void onSuccess(BaseEntity<VideoListEntity> data) {
                DialogHelper.dismissProgressDialog();
                if (data.getData() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                    attentionfragment.setListVideo(data.getData());
                }
            }
        });
    }

        //点赞的操作
        public void setLike(String s) {
            Map map = new HashMap();
            map.put("videoId", s);//longitude
            ShareConfig.getInstance().getApi().getlike(map).enqueue(new ICallBack<BaseEntity>() {
                @Override
                public void onSuccess(BaseEntity data) {

                }
            });
        }
    //获取评论数量
    public void getCommentNum(VideoBean videoData, ControllerView controllerView) {
        Map map = new HashMap();
        map.put("videoId", videoData.getVideoId());//longitude
         ShareConfig.getInstance().getApi().getCommentCount(map).enqueue(new ICallBack<BaseEntity<ShareDictEntity3>>() {
             @Override
             public void onSuccess(BaseEntity<ShareDictEntity3> data) {
                 if (data.getData()== null) {
                     return;
                 }
                 if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                     videoData.setCommentCount(Integer.parseInt(data.getData().getParam()));
                     attentionfragment.setCommentNum(videoData,controllerView);
                 }
             }
         });
    }

    /*
     * 视频播放次数实现
     * */
    public void getplayVideo(String videoId) {
        Map map = new HashMap();
        map.put("videoId",videoId );
         ShareConfig.getInstance().getApi().getplayVideos(map).enqueue(new ICallBack<BaseEntity>() {
             @Override
             public void onSuccess(BaseEntity data) {

             }
         });
    }

    public void deleteMyVideo(int id) {
        delectList = new ArrayList<>();
        delectList.add((long) id);
        DialogHelper.showProgressDialog(attentionfragment.getContext(), null, "删除中...", 0, true, null).setCanceledOnTouchOutside(false);
         ShareConfig.getInstance().getApi().getDeleteMyVideo(delectList).enqueue(new ICallBack<BaseEntity>() {
             @Override
             public void onSuccess(BaseEntity data) {
                 DialogHelper.dismissProgressDialog();
                 if (data.getData() == null) {
                     return;
                 }
                 if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                     MToast.showToast(attentionfragment.getContext(), "删除视频成功！");
                     attentionfragment.setDataList();
                 }
             }
         });
    }


}
